package com.cnyz.controller;

import cn.hutool.db.PageResult;
import com.cnyz.base.PageResponse;
import com.cnyz.base.ResponseResult;
import com.cnyz.dto.ExamDto;
import com.cnyz.service.ExamService;
import com.cnyz.vo.ExamVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/exam")
@ApiModel(description = "考试相关接口")
public class ExamController {

    @Autowired
    private ExamService examService;

    @PostMapping("/add")
    @ApiOperation(value = "添加考试")
    public ResponseResult addExam(@RequestBody ExamDto examDto) {
        examService.addExam(examDto);
        return ResponseResult.success("考试添加成功");
    }

    @GetMapping("/page")
    @ApiOperation(value = "分页查询考试")
    public ResponseResult getExamPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                      @RequestParam(defaultValue = "10") Integer pageSize,
                                      @RequestParam(required = false) String name
                                      ) {

        PageResponse<ExamVo> pageResult = examService.getExamPage(pageNum, pageSize, name);
        return ResponseResult.success("分页查询成功",pageResult);
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除考试")

    public ResponseResult deleteExam(@RequestParam Long id) {
        examService.deleteExam(id);
        return ResponseResult.success("考试删除成功");
    }

    @ApiOperation("为考试添加试卷")
    @PostMapping("/id/{id}/paper/{paper}")
    public ResponseResult setPaperToExam(@PathVariable Long id, @PathVariable Long paper) {
        examService.setPaperToExam(id, paper);
        return ResponseResult.success("试卷添加到考试成功");
    }



}
